<%@ page import="com.db.entity.Person" %>
<%@ page import="java.util.List" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"  %><%--
  Created by IntelliJ IDEA.
  User: w
  Date: 2021/7/5
  Time: 19:32
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
  <title>Title</title>
</head>
<body >


<%--<%List<Person> list = (List<Person>) request.getAttribute("Persons");%>--%>
<%--<%String username = (String)session.getAttribute("login");%>--%>

<h1 align='center'><font color="#7fffd4">联系人！！！！！</font></h1>
<h1 align='center'><font color='red'>欢迎回来！！！</font>${sessionScope.login}</h1>
<div style=\"width:100%;text-align:center>
  <form action ='${pageContext.request.contextPath}/selectData'  method ='post'>
    <select name='condition'>
      <option value='name' selected>姓名</option>
      <option value='mobile'>电话</option>
      <option value='address'>住址</option>
    </select>

    <input type= 'text' name='content'/>
    <input type= 'submit' value='搜索'/>
    <button type='button'  onclick="javascript:window.location.href='${pageContext.request.contextPath}/showPersons'">搜索所有联系人</button>
  </form>
</div>

<table border='1' align='center'>
  <tr>
    <td align=center>头像</td>
    <td align=center>id</td>
    <td align=center>姓名</td>
    <td align=center>生日</td>
    <td align=center> 性别 </td>
    <td align=center>联系方式 </td>
    <td align=center> 住址</td>
    <td colspan='2' align=\"center\">操作</td>
  </tr>
  <input type= 'button' value='安全退出' onclick="javascript:window.location.href='${pageContext.request.contextPath}/exitController'" style="float: right;"/>
  <%--<%for (Person persons : list)
      {%>--%>
  <c:forEach var="person" items="${requestScope.Persons}">
    <tr height = '30px'>
      <td><img style="width:95px;height: 95px;" src="${pageContext.request.contextPath}/upload_repository/${person.face}"></td>
      <td width = '60px' align="center">${person.id}</td>
      <td >${person.name}</td>
      <td width = '120px' align="center">${person.birthday}</td>
      <td width = '60px' align="center">${person.sex}</td>
      <td >${person.mobile}</td>
      <td width = '110px' align="center">${person.address}</td>
      <td><input type= 'button' value='删除' onclick="javascript:window.location.href='${pageContext.request.contextPath}/removePerson?personsId=${person.id}&rawFace=${person.face}'"/></td>
      <td><input type= 'button' value='修改' onclick="javascript:window.location.href='${pageContext.request.contextPath}/showPersonController?personsId=${person.id}'"/></td>
    </tr>
  </c:forEach>
  <tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td colspan='2' align='center'><input type = 'button' value='添加联系人' onclick=javascript:window.location.href='${pageContext.request.contextPath}/addPerson.jsp'></td></tr>
</table>
<br><br><br><br><br>

<%--<%Integer maxPage = (Integer)request.getAttribute("maxPage");--%>
<%
  String url = "/showPersons";

  String type =(String) session.getAttribute("type");

  if("name".equals(type)||"mobile".equals(type)||"address".equals(type)){
    url = "/selectPerson";
  }
%>
<%--<%Integer pageIndex = (Integer)request.getAttribute("pageIndex");%>--%>


<div style="width:100%;text-align:center;position:absolute; top: 760px;">
  <%--<%if(pageIndex>1){%>--%>
  <c:if test="${requestScope.pageIndex>1}">
    <button type='button'  onclick="javascript:window.location.href='${pageContext.request.contextPath}<%=url%>?pageIndex=${requestScope.pageIndex-1}'">上一页</button>
  </c:if> &nbsp; &nbsp; &nbsp;

  <%-- <%for( int i =1; i<=maxPage;i++){%>--%>
  <c:forEach var="i" begin="1" end="${requestScope.maxPage}" step="1"> &nbsp; &nbsp; &nbsp;
    <button type = 'button' onclick="javascript:window.location.href='${pageContext.request.contextPath}<%=url%>?pageIndex=${i}'">${i}</button>
  </c:forEach>
  <%--%if(pageIndex<maxPage){%>--%>
  <c:if test="${requestScope.pageIndex<requestScope.maxPage}">&nbsp; &nbsp; &nbsp;
    <button type='button'  onclick="javascript:window.location.href='${pageContext.request.contextPath}<%=url%>?pageIndex=${requestScope.pageIndex+1}'">下一页</button>
  </c:if>
</div>

</body>
</html>
